package com.atguigu.srb.sms.config;

import com.netflix.loadbalancer.AbstractLoadBalancerRule;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.Server;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.stereotype.Component;

import java.util.List;
//@Component
public class MyRandomLoadBalancer extends RandomRule {
    @Override
    public Server choose(ILoadBalancer lb, Object key) {
        //获取要远程访问的服务名 对应的所有的ip端口列表
//        List<Server> allServers = lb.getAllServers();
        //获取要远程访问的服务名 对应的所有可达的ip端口列表
        List<Server> reachableServers = lb.getReachableServers();
        int size = reachableServers.size();
        Server server = reachableServers.get(1);
        return server;
    }
}
